﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GDI_应用案例.Pages.Controls
{
    public abstract class DisposableBase : IDisposable
    {
        protected abstract void DisposeUnmanaged();
        protected abstract void DisposeManaged();

        #region 垃圾释放
        private bool _disposed;
        private object _obj = new object();
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed) return;

            lock (_obj)
            {
                if (_disposed) return;

                if (disposing)
                    DisposeManaged();

                DisposeUnmanaged();

                _disposed = true;
            }
        }
        ~DisposableBase()
        {
            Dispose(false);
        }
        #endregion
    }
}
